package com.chookss.home.gallery.adapter;

import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chookss.R;
import com.chookss.base.BaseViewHolderEx;
import com.chookss.home.entity.GalleryHotSearchEntity;
import com.chookss.home.gallery.GalleryListActivity;
import com.chookss.tools.GlideUtils;
import com.chookss.tools.Utils;
import com.chookss.view.MyRoundLayout;

import java.util.List;

import io.reactivex.annotations.Nullable;

public class GallerySearchHotTagAdapter extends BaseQuickAdapter<GalleryHotSearchEntity.TagListBean, BaseViewHolderEx> {
    private Activity context;
    private int width;
    private int type = 1;//

    public GallerySearchHotTagAdapter(int layoutResId, Activity context, @Nullable List<GalleryHotSearchEntity.TagListBean> data, int type) {
        super(layoutResId, data);
        this.context = context;
        this.type = type;
        width = (Utils.getScreenWidthPixel(context) - Utils.dip2px(context, 48)) / 3;
    }

    @Override
    protected void convert(BaseViewHolderEx helper, GalleryHotSearchEntity.TagListBean item) {
        MyRoundLayout rlBg = helper.getView(R.id.rlBg);
        ImageView ivBg = helper.getView(R.id.ivBg);
        TextView tvTagTitle = helper.getView(R.id.tvTagTitle);
        TextView tvTagNum = helper.getView(R.id.tvTagNum);
        ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) rlBg.getLayoutParams();
        params.height = width;
        params.width = width;
        rlBg.setLayoutParams(params);
        GlideUtils.loadCustomRound(context,item.getImagePath(),ivBg,15);
        tvTagTitle.setText(item.getTagName());
        tvTagNum.setText(Utils.changeNumber(item.getImageNum())+"");
        helper.getItemView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, GalleryListActivity.class);
                intent.putExtra("data", tvTagTitle.getText().toString());
                intent.putExtra("tagCode",item.getTagCode());
                intent.putExtra("catalogCodes","");
                intent.putExtra("city","");
                intent.putExtra("createTime","");
                intent.putExtra("searchType", 2+"");
                intent.putExtra("roleType", 1);
                context.startActivity(intent);
            }
        });
    }
}
